package org.example.c2;

/**
 * @author liu-rui
 * @date 2020/6/3 下午5:40
 * @description 通过synchronized解决线程安全问题
 * @since
 */
public class Demo15 {
    public static void main(String[] args) throws InterruptedException {
        SumTask sumTask = new SumTask();

        sumTask.exec(new Counter());
    }

    static class Counter implements ICounter {
        private int sum;

        @Override
        public synchronized void add(int data) {
            sum += data;
        }

        @Override
        public synchronized int getSum() {
            return sum;
        }
    }
}
